# 字典操作
# 字典的定义，能够通过 key 找到 value


# 定义一个空字典
# empty_dict = {}
# print(f"type dict = {type(empty_dict)}")
"""
# 数据是怎么存储的 {key:value,key:value},key可以是任意类型，value也可以是任意类型
person_dict = {"name":"吴彦祖","age":18,"car":"红色","money":1.88}

print(f"我的名字叫{person_dict['name']}")
print(f"今年{person_dict['age']}岁！")
print(f"我有一辆{person_dict['car']}的跑车！")
print(f"我有{person_dict['money']}亿！！！")

class Person:
    name: str = ""
    age: int = ""
    money: float = 0

    def __init__(self, name, age, money):
        self.name = name
        self.age = age
        self.money = money

    def introduce(self):
        print(f"我的名字叫{self.name}, 今年{self.age}, 拥有{self.money}亿！")

test_dict = {9527:Person("吴彦祖","19","88.888")}
one_person = test_dict[9527]
one_person.introduce()
"""
"""
person_dict = {"name":"吴彦祖","age":18,"car":"红色","money":1.88}
# 如何对字典里面的key-value 进行遍历
for key,value in person_dict.items():
    print(f"key = {key}  value = {value}")
print("---------------------------")

# 如何对字典增加数据
person_dict["婚姻状况"] = "已婚"
for key,value in person_dict.items():
    print(f"key = {key}  value = {value}")

# 查询某个key 有没有在 字典里面
print("name" in person_dict)

# 修改某一个数据
person_dict["age"] = "35"

print("---------------------------")

# 数据删除
del person_dict["婚姻状况"]

for key,value in person_dict.items():
    print(f"key = {key}  value = {value}")
"""

# 字典的嵌套
dict_car = {"brand":"法拉利", "price":"400w"}
person_dict = {"name":"吴彦祖","age":18,"car":dict_car,"money":1.88}
person_dict2 = {"name":"吴彦祖","age":18,"car":dict_car["brand"],"money":1.88}
print(person_dict)
print(person_dict2)
